#include "Boss.h"
#include "Box.h"
#include "RSManager.h"
#include "Sprite.h"

Boss::Boss(Box* box) : Object(box, ObjEnemy_STATIC)
{
	_sprite = RSManager::getInstance()->getSprite(BOSS);
	_explode = RSManager::getInstance()->getSprite(BOSS_EXPLODE);
	_eff1 = RSManager::getInstance()->getSprite(BOSS_EFF1);
	_eff2 = RSManager::getInstance()->getSprite(BOSS_EFF2);
	_eff3 = RSManager::getInstance()->getSprite(BOSS_EFF3);
	_eff4 = RSManager::getInstance()->getSprite(BOSS_EFF4);
	_eff5 = RSManager::getInstance()->getSprite(BOSS_EFF5);
	_eff6 = RSManager::getInstance()->getSprite(BOSS_EFF6);
	_eff7 = RSManager::getInstance()->getSprite(BOSS_EFF7);
	_eff8 = RSManager::getInstance()->getSprite(BOSS_EFF8);
	_eff9 = RSManager::getInstance()->getSprite(BOSS_EFF9);
	_eff10 = RSManager::getInstance()->getSprite(BOSS_EFF10);

	delay = 0;	
	_isAlive = true;
	_drawEffect = false;
	_hits = 32;
}


Boss::~Boss(void)
{
}

void Boss::update()
{	
	delay += GAME_TIME;	
	if(_isAlive)
	{
		if(delay >= 100)
		{
			delay = 0;
			_sprite->Next();		
			if(_hits <= 0)							
			{
				_sprite = _explode;			
				if(_sprite->GetCurrentIndex() == 5)
				{
					_drawEffect = true;
					_isAlive = false;
				}
			}
		}
	}
	if (_drawEffect && _eff1->GetCurrentIndex() != 5)
	{
		if(delay >= 100)
		{
			delay = 0;
			_eff1->Next();
			_eff2->Next();
			_eff3->Next();
			_eff4->Next();
			_eff5->Next();
			_eff6->Next();
			_eff7->Next();
			_eff8->Next();
			_eff9->Next();
			_eff10->Next();
		}
	}
}

void Boss::render()
{
	_sprite->Render(_box->_position);
	if (_drawEffect)
	{
		_eff1->Render(_box->_position + D3DXVECTOR2(-32, 32));
		_eff2->Render(_box->_position + D3DXVECTOR2(32, 32));
		_eff3->Render(_box->_position + D3DXVECTOR2(96, 32));
		_eff4->Render(_box->_position + D3DXVECTOR2(160, 32));
		_eff5->Render(_box->_position + D3DXVECTOR2(224, 32));
		_eff6->Render(_box->_position + D3DXVECTOR2(-32, -32));
		_eff7->Render(_box->_position + D3DXVECTOR2(32, -32));
		_eff8->Render(_box->_position + D3DXVECTOR2(93, -32));
		_eff9->Render(_box->_position + D3DXVECTOR2(160, -32));
		_eff10->Render(_box->_position + D3DXVECTOR2(224, -32));
	}
}

Box* Boss::getCollisionBox()
{
	_colBox->_position.x = _box->_position.x + _box->_size.x / 2;
	_colBox->_position.y = _box->_position.y + _box->_size.y / 2;
	_colBox->_size.x = _box->_size.x /2;
	_colBox->_size.y = _box->_size.y /2;
	_colBox->_v = _box->_v;
	return _colBox;
}
